package com.feicheng.iou.controller.weChat;

import com.feicheng.iou.bean.InformationBean;
import com.feicheng.iou.constant.StatusCodeConstant;
import com.feicheng.iou.exception.SystemExceptionV110;
import com.feicheng.iou.result.ResultInfoV110;
import com.feicheng.iou.service.weChatService.WeChatPayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;

@RestController
@Slf4j
@RequestMapping("/iou")
public class ApiPayController {

    @Autowired
    private WeChatPayService weChatPayService;

    /**
     * @param
     * @return ResultInfoV110
     * @description 下单并且支付,主要是做两次签名
     */
    @PostMapping("/wxPayH5")
    public ResultInfoV110 pay(String openid,String attachPaymentId,String totalFee) throws Exception {
        log.info("进入ApiPayController的pay方法,参数openid为"+openid+",参数attachPaymentId为"+attachPaymentId+"参数totalFee为"+totalFee);
        if(openid == null){
            throw new SystemExceptionV110(InformationBean.setInformationBean(StatusCodeConstant.F002,"统一下单openid"));
        }
        if(attachPaymentId == null ){
            throw new SystemExceptionV110(InformationBean.setInformationBean(StatusCodeConstant.F002,"分期期数"));
        }
        if(totalFee == null){
            throw new SystemExceptionV110(InformationBean.setInformationBean(StatusCodeConstant.F002,"应付金额"));
        }
        //统一下单
        return  weChatPayService.pay(openid, attachPaymentId, totalFee);
    }
}






